package com.code2roc.jarmanage.util;

import org.yaml.snakeyaml.Yaml;

import java.io.File;
import java.io.FileInputStream;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map;

public class ConfigUtil {
    public static String getConfigValue(String configName){
        String configValue = "";
        try{
            Yaml yaml = new Yaml();
            InputStream resourceAsStream = new FileInputStream(new File("resources"+File.separator+"application.yml"));
            Map obj = yaml.load(resourceAsStream);
            Map<String,Object> param = (Map) obj.get("jarmanage");
            configValue = ConvertUtil.convert2String(param.get(configName));
        }catch (Exception e){
            LogUtil.error(e);
        }
        return configValue;
    }

    public static String getConfigValue(String name,String configName){
        String configValue = "";
        try{
            Yaml yaml = new Yaml();
            InputStream resourceAsStream = new FileInputStream(new File("resources"+File.separator+"application.yml"));
            Map obj = yaml.load(resourceAsStream);
            Map<String,Object> param = (Map) obj.get(name);
            configValue = ConvertUtil.convert2String(param.get(configName));
        }catch (Exception e){
            LogUtil.error(e);
        }
        return configValue;
    }
}
